<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
class User extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		$this->admin->isLogin ( site_url ( 'login' ) );
		$this->load->model ( 'user_model' );
	}
	public function index($page=1){
		$whereArr = array();
		$count = $this->user_model->count ( $whereArr );
		$params = array(
				"url_template" => site_url ( 'User/index/{page}' ),
				"page_count" => $count,
				"page_now" => $page,
				"page_size" => 10
		);
		$params["total_pages"] = ceil ( $params['page_count'] / $params['page_size'] );
		$this->load->library ( 'paging', $params );
		$user_list = $this->user_model->result ( $whereArr, $page, $params['page_size'] );
		$data['user_list'] = $user_list;
		$this->load->view('user_index',$data);
	}
	public function del($uid=0){
		$whereArr=array("uid"=>$uid);
		$result = $this->user_model->delete($whereArr);
		if($result){
			$data['status'] = 1;
			$data['info'] = "用户删除成功!";
 		}else{
			$data['status'] = 0;
			$data['info'] = "用户删除失败!";
		}
		echo json_encode($data);
	}
	public function forbid($uid=1){
		$whereArr = array("uid"=>$uid);
		$dataArr = array("status"=>0);
		$result = $this->user_model->update($dataArr,$whereArr);
		if($result){
			$data['status'] = 1;
			$data['info'] = "用户禁用成功!";
		}else{
			$data['status'] = 0;
			$data['info'] = "用户禁用失败!";
		}
		echo json_encode($data);
	}
	public function resume($uid=1){
		$whereArr = array("uid"=>$uid);
		$dataArr = array("status"=>2);
		$result = $this->user_model->update($dataArr,$whereArr);
		if($result)
		{
			$data['info'] = "用户启用成功!";
			$data['status'] = 1;
		}else{
			$data['status'] = 0;
			$data['info'] = "用户启用失败!";
		}
		echo json_encode($data);
	}
	public function duoresume(){
		$ids = $this->input->post('ids');
		if(empty($ids))
		{
			$flag =array('status'=>-1,'info'=>'请选择数据!!');
		}else{
			$dataArr=array("status"=>2);
			$result=$this->user_model->update_in($dataArr,'uid',$ids);
			if($result){
				$flag = array('status'=>1,'info'=>'用户启用成功!!');
			}else{
				$flag = array('status'=>0,'info'=>'用户启用失败!!');
			}
		}
		echo json_encode($flag);
	}
	public function duoforbid(){
		$ids = $this->input->post('ids');
		if(empty($ids))
		{
			$flag =array('status'=>-1,'info'=>'请选择数据!!');
		}else{
			$dataArr=array("status"=>0);
			$result=$this->user_model->update_in($dataArr,'uid',$ids);
			if($result){
				$flag = array('status'=>1,'info'=>'用户禁用成功!!');
			}else{
				$flag = array('status'=>0,'info'=>'用户禁用失败!!');
			}
		}
		echo json_encode($flag);
	}
	public function duodel(){
		$ids = $this->input->post('ids');
		if(empty($ids))
		{
			$flag =array('status'=>-1,'info'=>'请选择数据!!');
		}else{
			$result=$this->user_model->allDelete('uid',$ids);
			if($result){
				$flag = array('status'=>1,'info'=>'删除用户成功!!');
			}else{
				$flag = array('status'=>0,'info'=>'删除用户失败!!');
			}
		}
		echo json_encode($flag);
	}
}